// Fill out your copyright notice in the Description page of Project Settings.


#include "LobbyGameMode.h"
#include"GameFramework/GameStateBase.h"
#include"MultiplayerSessionsSubSystem.h"

void ALobbyGameMode::PostLogin(APlayerController* NewPlayer)
{
	Super::PostLogin(NewPlayer);
	if (GameState)
	{
		int32 Num_Of_Players=GameState.Get()->PlayerArray.Num();

		UGameInstance* GameInstance = GetGameInstance();
		if (GameInstance)
		{
			UMultiplayerSessionsSubSystem* SubSystem = GameInstance->GetSubsystem<UMultiplayerSessionsSubSystem>();
			check(SubSystem);

			if (Num_Of_Players == SubSystem->DesiredNumPublicConnection)
			{
				bUseSeamlessTravel = true;
				UWorld* world = GetWorld();

				FString MatchType = SubSystem->DesiredMatchType;
				if (MatchType == "FreeForAll")
				{
					world->ServerTravel(FString("/Game/Maps/BlasterMap_FFR?listen"));
				}
				else if(MatchType=="Teams")
				{
					world->ServerTravel(FString("/Game/Maps/BlasterMap_Team?listen"));
				}
				else if(MatchType=="Flag")
				{
					world->ServerTravel(FString("/Game/Maps/BlasterMap_Flag?listen"));
				}
				
			}
		}
	}
}
